Skip to content

下载文件扩展 - HttpDownloadFileEx

函数简介

下载文件,支持断点续传、进度回调、重试和超时设置。

接口名称

HttpDownloadFileEx

DLL调用

c
int32_t HttpDownloadFileEx(int64_t instance, const char* url, const char* save_path, DownloadCallback callback, int64_t user_data, int32_t max_retries, int32_t connect_timeout_sec, int32_t read_timeout_sec);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
url字符串完整URL。
save_path字符串本地保存路径。
callbackDownloadCallback下载进度回调函数。
user_data长整数型传给callback的用户数据。
max_retries整数型断线后最大重试次数。
connect_timeout_sec整数型连接超时秒数,0使用默认值。
read_timeout_sec整数型读取超时秒数,0使用默认值。

使用场景

场景推荐参数
大文件下载max_retries=3~5read_timeout_sec=60~120
不稳定网络增大 max_retries 和超时
内网快速下载超时传 0 使用默认值

HttpDownloadFile 的差异:Ex 版额外支持 断线自动重试连接/读取超时 配置。

示例

c
void DownloadCallback(int64_t current, int64_t total, int64_t speed, int64_t user_data);
参数名类型说明
current长整数型已下载字节数
total长整数型总字节数(0表示未知)
speed长整数型当前下载速度(字节/秒)
user_data长整数型由调用方传入的用户数据

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// max_retries=3, connect_timeout=10s, read_timeout=60s
int ret = ola.HttpDownloadFileEx(
    "https://example.com/large.zip",
    "D:\\downloads\\large.zip",
    nullptr, 0,
    3, 10, 60
);
if (ret == 0) {
    // 大文件/不稳定网络推荐 Ex 版
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.HttpDownloadFileEx("https://example.com/large.zip", @"D:\downloads\large.zip", null, 0, 3, 10, 60);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.HttpDownloadFileEx("https://example.com/large.zip", r"D:\downloads\large.zip", None, 0, 3, 10, 60)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\\downloads\large.zip", null, 0, 3, 10, 60);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\\downloads\large.zip", nil, 0, 3, 10, 60)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.http_download_file_ex("https://example.com/large.zip", "D:\\downloads\large.zip", None, 0, 3, 10, 60);
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\\downloads\large.zip", 0, 0, 3, 10, 60)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\downloads\large.zip", 0, 0, 3, 10, 60)
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.HttpDownloadFileEx ("https://example.com/large.zip", "D:\downloads\large.zip", 0, 0, 3, 10, 60)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\downloads\large.zip", null, 0, 3, 10, 60);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\downloads\large.zip", 0, 0, 3, 10, 60)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.HttpDownloadFileEx("https://example.com/large.zip", "D:\\downloads\large.zip", nullptr, 0, 3, 10, 60);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
int ret = HttpDownloadFileEx(instance, "https://example.com/large.zip", "D:\\downloads\\large.zip", 0, 0, 3, 10, 60);
csharp
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
int ret = HttpDownloadFileEx(instance, "https://example.com/large.zip", "D:\\downloads\\large.zip", 0, 0, 3, 10, 60);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
int ret = HttpDownloadFileEx(instance, "https://example.com/large.zip", "D:\\downloads\\large.zip", 0, 0, 3, 10, 60);

返回值

返回值说明
0成功。
< 0失败,错误码与相关接口一致。

注意事项

项目说明
支持断点续传和自动重试支持断点续传和自动重试。
重试次数不包括首次尝试重试次数不包括首次尝试。
默认值超时设置为0时使用默认值(通常为30秒)。
适合下载大文件或网络不稳定的场景适合下载大文件或网络不稳定的场景。